<?php

/**
 * Botenmarkt Front-end
 *
 * Domain Objects
 * 
 * Accound domain object File
 * 
 * @category    botenmarkt_front
 * @package     library
 * @subpackage  domainObjects
 * 
 * @author      valerii lazarevych <valeriy.fremar@gmail.com>
 * @copyright   Copyright(c) Fremar ltd.
 * 
 * @license     default
 * @version     5:07:59 PM | Mar 15, 2012
 */

/**
 * Accounts domain object Class
 * 
 * It's OOP entity represent application user
 */
class Accounts_domainObject     extends domainObject
{
    /**
     * User email
     * 
     * @var string
     */
    public      $email                  =       null;
    
    /**
     * User's phone number
     * 
     * @var string
     */
    public      $phoneNumber            =       null;

    /**
     * User password
     * 
     * @var string
     */
    public      $password               =       null;
    
    /**
     * User online publish status
     * 
     * @var bool
     */
    public      $accStatus              =       null;
    
    /**
     * Time range start point 
     * 
     * When it comes user can be active
     * & produce any actions he can
     * 
     * @var int |   Unix time
     */
    public      $activeFrom             =       null;
    
    /**
     * Time range end point
     * 
     * When it comes user can do nothing
     * 
     * @var int |   Unix time
     */
    public      $activeTo               =       null;
    
    /**
     * User type
     * 
     * 0 - private
     * 1 - company
     * 
     * @var bool
     */
    public      $advertiserType         =       null;
    
    /**
     * Is user email available to public view
     * 
     * @var bool
     */
    public      $publishEmail           =       null;
    
    /**
     * Is user's phone number is available for public view
     * 
     * @var bool
     */
    public      $publishPhone           =       null;

    /**
     * Total ads user have added
     * 
     * @var int
     */
    public      $totalAdsNo             =       null;
    
    /**
     * Total ads user have placed
     * 
     * @var int
     */
    public      $placedAdsNo            =       null;
    
    /**
     * $adsPerCategory
     * 
     * @var int
     */
    public      $adsPerCategory         =       null;
    
    /**
     * Time user last login
     * 
     * @var int |   Unix time
     */
    public      $lastLogin              =       null;
    
    /**
     * Time user was created
     * 
     * @var int |   Unix time
     */
    public      $created                =       null;
    
    /**
     * Security code
     * 
     * @var string
     */
    public      $securityCode           =       null;
    
    /**
     * Is user a spammer
     * 
     * @var bool
     */
    public      $spam                   =       null;
    
    /**
     * is user notified
     * 
     * @var bool
     */
    public      $notified               =       null;
    
    /**
     * Get user advertiser type 
     * 
     * @return int or null
     */
    public function userAdvertiserType()
    {
        return $this->advertiserType;
    }
    
    /**
     * Get high time point the user can be active
     * 
     * @return int  | Unix time
     */
    public function userActiveTo()
    {        
        return $this->activeTo;
    }
    
    /**
     * Get email
     * 
     * @return string
     */
    public function userEmail()
    {
        return $this->email;
    }
    
    /**
     * Get password
     * 
     * @return string
     */
    public function userPassword()
    {
        return $this->password;
    }
    
    /**
     * Get last login time
     * 
     * @param string $format
     * @return string
     */
    public function userLastLogin($format = '')
    {
        if ($format)
            return  date($format, $this->lastLogin);
        
        return $this->lastLogin;        
    }
    
    /**
     * Note the last user visit
     */
    public function noteLastVisit()
    {
        $this->lastLogin    =   time();        
        $this->save();
    }


    /**
     * Is user can be active & and produce actions he can as usually
     * 
     * or it can do nothing
     * 
     * @return bool
     */
    public function isUserActive()
    {
        return $this->activeTo > time();
    }
    
    public function usersPhoneNumber()
    {
        return $this->phoneNumber;
    }
    
    public function isUserPhoneVisible()
    {
        return $this->publishPhone;
    }
}

